<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ page import="com.system.uitls.CommonUtil"%>
<%@ include file="../common.jsp" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<%

	pageContext.setAttribute("uuid", CommonUtil.getUuid());
	pageContext.setAttribute("path", request.getContextPath());
%>
<html>
  <head>
    <title>数据导入</title>
     <style type="text/css">
    	.td-filename {
			font-size: 12px;
			height: 20px;
			background-color: #fff;
			border: 1px solid #B5B8C8;
			padding: 0px !important;
			padding: 0px;
			margin-top: 0px;
			vertical-align: top;
			background: #FFFFFF url(${path}/images/find.gif) repeat-x scroll right top;
		}
		
    </style>
    <script type="text/javascript" src="${path}/js/public/jquery.ocupload-1.1.2.js"></script>
    <script type="text/javascript">
    
    	var newResName = "";
    	
	    function filterCheck(file, extension, filter) {
	    	return ((filter=='null') || (filter.indexOf(extension)>=0))
	    }
     
	    function importXls(file)
	    {
	    	var filePath = newResName;
	     	var type = $("input[name='type']:checked").val();
	     	ajax.remoteCall("com.system.dao.PersonDao:importCardXls",[type,filePath],function(reply){

				var result = reply.getResult();
				alert(result.value);
				dlg =  Dialog.getInstance("viewSheet");
				if(result.type == "success")
				{
					var parent = dlg.getParam("window");
					parent.mygrid.reload();
				}
				dlg.close();
		    });
	    }
	    
	    
    	$().ready(function(){
    		uploadFile = new AjaxUpload('#uploadFile_div', 
    		{
				action: '${path}/upload',
				onChange: 
					function(file, extension) { 
	 					if (!filterCheck(file, extension, 'xls,xlsx')) {				
	 						alert('文件类型不符合要求, 请重新选择(xls,xlsx)类型文件.'); 
	 						return false; 
	 	 				} else{
	 	 					var len = file.lastIndexOf(".");
	 	 					var type = file.substring(len, file.length);
	 	 					newResName = "${uuid}." + type;
	 	 					this.setData({ uuid : newResName});
	 	 					document.getElementById('uploadFile_div').innerHTML = file.substring(0,12) + "...";
	 						this.submit();
	 					}
				},onComplete: function(file, response) {
					importXls(file);
				}
    		});

    	});
   
    </script>
  </head>
  <body style="overflow: hidden;">
  	<center>
	  	<form id="winForm">
			<table border="0" cellpadding="0" cellspacing="0" style="margin-left: 10px">
				<tr height="40px">
					<td width="80px">上传文件：</td>
					<td>	
						<table width="180px" height="20" class="uploadtable" id="uploadFile_table">
							<tr>
								<td width="180px" class="td-filename">
									<div class="fileupload " id="uploadFile_div" style="width: 164px;"></div>
								</td>
							</tr>
						</table>
					</td>
				</tr>
				<tr height="30px">
					<td width="80px">模板下载：</td>
					<td>
						<a href="${path}/download?fileName=card.xls">点击下载模板</a>
					</td>
				</tr>
		  	</table>
	  	</form>
  	</center>
  </body>
</html>
